package ylsb.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ylsb.service.DailiangchuangxinService;
import ylsb.support.JsonResult;
import ylsb.support.PageInfo;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("dailiangchuangxin")
public class DailiangchuangxinController {
    @Resource
    DailiangchuangxinService ddService;

    public Logger log = LoggerFactory.getLogger(YltpBaofeiController.class);

    @RequestMapping("findDailiangchuangxinlist")
    public JsonResult<?> findDailiangchuangxinlist(@RequestParam("xiangmuid") String ppXiangmuId, @RequestParam("pageindex") int ppPageIndex,
                                                  @RequestParam("pagesize") int ppPageSize){
        try {

            List<Map<String,Object>> mmList = ddService.findDailiangchuangxinByXiangmuId(ppXiangmuId,ppPageIndex,ppPageSize);
            Integer mmCount = ddService.getChuangxinCount(ppXiangmuId);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

            Map<String, Object> mmReturnMap = new HashMap<String, Object>();
            mmReturnMap.put("ChuangxinchanpinList", mmList);
            mmReturnMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmReturnMap);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("dailiangchuangxin/findDailiangchuangxinlist:error",e);
            return JsonResult.getErrorResult("dailiangchuangxin/findDailiangchuangxinlist:error " + e.getMessage());
        }

    }
    @RequestMapping("delete")
    public JsonResult<?> delete(@RequestParam("xiangmuid") String ppxiangmuId){
        try {
            return ddService.deleteByxiangmuId(ppxiangmuId)==true? JsonResult.getSuccessResult("删除材料成功")
                    : JsonResult.getErrorResult("删除材料失败");
        }catch (Exception e) {
            e.printStackTrace();
            log.error("dailiangchuangxin/delete:error",e);
            return JsonResult.getErrorResult("dailiangchuangxin/delete:error " + e.getMessage());
        }
    }

    @RequestMapping("findbiaojuelist")
    public JsonResult<?> findBiaojueList(@RequestParam("xiangmuid") String ppXiangmuId,@RequestParam("userid") String ppUserId, @RequestParam("pageindex") int ppPageIndex,
                                         @RequestParam("pagesize") int ppPageSize){
        try {

            List<Map<String,Object>> mmList = ddService.findChuangxinBiaojueByXiangmuId(ppXiangmuId,ppUserId,ppPageIndex,ppPageSize);
            Integer mmCount = ddService.countChuangxinBiaojueByXiangmuId(ppXiangmuId,ppUserId);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

            Map<String, Object> mmReturnMap = new HashMap<String, Object>();
            mmReturnMap.put("Biaojuelist", mmList);
            mmReturnMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmReturnMap);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("dailiangchuangxin/findbiaojuelist:error",e);
            return JsonResult.getErrorResult("dailiangchuangxin/findbiaojuelist:error " + e.getMessage());
        }

    }


}
